package br.com.millenium.service.funcionario.processaction;

import br.com.millenium.domain.manager.MilleniumManagerFactory;
import lumis.doui.processaction.ProcessActionHandler;
import lumis.portal.PortalException;

@SuppressWarnings("rawtypes")
public class CheckDuplicateFuncionarioProcessActionHandler extends ProcessActionHandler
{
	@Override
	public void processAction() throws PortalException 
	{
		String funcionarioMatricula = (String)getParameter ( "matricula" );
		String funcionarioCPF       = (String)getParameter ( "cpf"       );
		String funcionarioRG        = (String)getParameter ( "rg"        );
		String funcionarioId        = (String)(getParameter( "id"        ) == null ? "" : getParameter( "id" ));
		
		if( MilleniumManagerFactory.getFuncionarioManager().isDuplicateFuncionarioMatricula( funcionarioId, funcionarioMatricula, transaction))
			throw new PortalException( "STR_FUNCIONARIOMATRICULA_EXISTS;", getResource() );
		else if( MilleniumManagerFactory.getFuncionarioManager().isDuplicateFuncionarioCPF( funcionarioId, funcionarioCPF, transaction))
			throw new PortalException( "STR_FUNCIONARIOCPF_EXISTS;", getResource() );
		else if( MilleniumManagerFactory.getFuncionarioManager().isDuplicateFuncionarioRG( funcionarioId, funcionarioRG, transaction))
			throw new PortalException( "STR_FUNCIONARIORG_EXISTS;", getResource() );
	}
}
